import java.util.Arrays;
import java.util.Set;
import java.util.HashSet;

public class AllSort1 {

	public static void main(String[] args) {
		System.out.println(Arrays.toString(permutation("RRL")));
	}

	private static String[] permutation(String orginal) {
		Set<String> set = new HashSet<String>();
		String[] str = new String[1];

		if (orginal.length() == 1) {
			str[0] = orginal;
			return str;
		} else {
			for (int i = 0; i < orginal.length(); i++) {
				String s = orginal.charAt(i) + "";
				String result = "";
				String resultA = result + s;
				String leftS = orginal.substring(0, i)
						+ orginal.substring(i + 1, orginal.length());
				for (String element : permutation(leftS)) {
					result = resultA + element;
					set.add(result);
				}
			}
			return (String[]) set.toArray(new String[set.size()]);
		}
	}

	private static boolean move(String str, int[][] a, int[][] b) {
		int k, j = 0;
		int temp = 0;
		for (k = 0; k < 5; k++) {
			for (j = 0; j < 5; j++) {

				if (a[k][j] == 0) {
					break;
				}
				break;
			}
		}

		for (int i = 0; i < str.length(); i++) {
			switch (str.charAt(i)) {
			case 'R':
				if(j==4){
					continue;
				}else{
					temp = a[k][j+1];
					a[k][j+1] = a[k][j];
					a[k][j] = temp;
					j++;
				}
			case 'L':
				if(j==0){
					continue;
				}else{
					temp = a[k][j-1];
					a[k][j-1] = a[k][j];
					a[k][j] = temp;
					j--;
				}
			case 'U':
				if(k==0){
					continue;
				}else{
					temp = a[k-1][j];
					a[k-1][j] = a[k][j];
					a[k][j] = temp;
					k--;
				}
			case 'D':
				if(k==4){
					continue;
				}else{
					temp = a[k+1][j];
					a[k+1][j] = a[k][j];
					a[k][j] = temp;
					k++;
				}
				
			}
			
		}
		
		if(a.equals(b)){
			return true;
		}else{
			return false;
		}
	}
}
